package com.examples.control;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class MultiLineText {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		/* Creating a Display */
		Display display = Display.getDefault();

		/* Adding a Shell in the Display */
		Shell shell = new Shell(display);
		shell.setText("Shell");

		/* Creating a Label */
		Label label = new Label(shell, SWT.NONE);
		label.setText("Text field");
		label.pack();
		label.setBounds(0, 0, 50, 20);

		/* Creating a multiline text field and attaching layout to it */
		Text text = new Text(shell, SWT.MULTI);
		text.setText("This is the\n multiline\n text we need");
		text.pack();
		text.setBounds(0, 20, 100, 60);

		/* Creating a button and attaching layout to it */
		Button button = new Button(shell, SWT.PUSH);
		button.pack();
		button.setText("Button");
		button.setBounds(0, 80, 50, 20);

		/* Adding listeners to the button selected */
		SelectedListener selectedListener = new SelectedListener();
		button.addSelectionListener(selectedListener);

		/* Adding traverse Listener to text */
		TraversalListener traversalListener = new TraversalListener();
		text.addTraverseListener(traversalListener);

		/* Telling the shell about the default button */
		shell.setDefaultButton(button);

		/* Setting the preferred size of the shell */
		shell.pack();

		/* Opening the shell */
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}

		//display.dispose(); //Commented only for SWTShowcase application.

	}

}
